{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8806ef17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "转换完成，已保存到 train_converted.json\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "input_file = \"train.jsonl\"\n",
    "output_file = \"train_converted.json\"\n",
    "\n",
    "data = []\n",
    "with open(input_file, \"r\", encoding=\"utf-8\") as f:\n",
    "    for line in f:\n",
    "        line = line.strip()\n",
    "        if not line:\n",
    "            continue\n",
    "        obj = json.loads(line)\n",
    "        for conv in obj[\"conversation\"]:\n",
    "            data.append({\n",
    "                \"instruction\": conv[\"human\"],\n",
    "                \"input\": \"\",\n",
    "                \"output\": conv[\"assistant\"]\n",
    "            })\n",
    "\n",
    "with open(output_file, \"w\", encoding=\"utf-8\") as f:\n",
    "    json.dump(data, f, ensure_ascii=False, indent=2)\n",
    "\n",
    "print(f\"转换完成，已保存到 {output_file}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
